﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using DVK.SP2007.Constants;

namespace DVK.SP2007.Controls
{
    /// <summary>
    /// Shows mapped metadata in a listview with Source, Target and Value columns.
    /// </summary>
    public partial class MappedMetadataViewer : System.Web.UI.UserControl
    {
        /// <summary>
        /// Gets or sets the mapping level.
        /// </summary>
        /// <value>The mapping level.</value>
        public Fields.DvkMappingLevel.DvkMappingLevelChoices MappingLevel { get; set; }
        /// <summary>
        /// Gets or sets the identifier.
        /// </summary>
        /// <value>The identifier.</value>
        public string Identifier { get; set; }
        /// <summary>
        /// Gets or sets the mapped metadata provider.
        /// </summary>
        /// <value>The mapped metadata provider.</value>
        public IMappedMetadataProvider MappedMetadataProvider { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                RefreshMetadata();
            }
        }

        /// <summary>
        /// Refreshes the metadata in the listview with data from MappedMetadataProvider.
        /// </summary>
        public void RefreshMetadata()
        {
            List<MappedMetadata> mappedMetadata = new List<MappedMetadata>();
            if (MappedMetadataProvider != null)
                mappedMetadata = MappedMetadataProvider.GetMappedMetada(MappingLevel, Identifier);

            this.listMappedMetadata.DataSource = mappedMetadata;
            this.listMappedMetadata.DataBind();
        }
    }


}